final color colorMainBg = #8CCBD6;

boolean scanMode = true; // 2 modes (scan mode, recording mode)

/*
https://www.douyin.com/shipin/7325617018244171803
 car gesture recognition
 
 handwriting_recognize
 
 draw a 'tick' and a 'cross' on the touch screen (my HP laptop ENVY is touch screen), then use diff (abs) to recognize it. show 'happy' or 'cry' face, or '?' if can recognize it.
 the 'tick' and 'cross' are pre-recorded in advanced. also use this application to make the recording.
 this project similiar wiht the 'diff2', same theory, just another usage demo case of diff abs or diff power 2
 */

// =========== setup =========== //
void setup() {
  size(1200, 700);
  smooth();
  textSize(40);
  fill(#B2F2F5);

  drawArea = new  cdrawArea(250, 250, 475, 375);

  if (scanMode) {
    println("scan mode ready...\n");
    println("press 't' or 'c' to show pre-recorded tick & cross trace");
    thread("threadScan");
    thread("threadPaintDot");
  } else {
    println("press 'r' to trigger recording");
    println("to make it simple, no drawing trace shown in the box\n");
  }
}

// =========== draw =========== //
void draw() {
  background(colorMainBg);

  text("Tick/Cross detector demo. V1.0. Chuyi Li. Feb 2025", 20, 40);
  drawArea.paint();
}

// =========== mouseClicked =========== //
void mouseClicked() {
  // println(mouseX + " " + mouseY); // for debug usage
}

// =========== keyPressed =========== //
void keyPressed() {
  if (!scanMode) {
    if (key == 'r') {
      drawArea.recStart(); // press 'r' to trigger rec mode
    }
  } else if (!drawArea.isShowingPreRecTrace()) {
    if (key == 't' || key == 'c') { // show Tick or Cross pre-recorded trace
      drawArea.showPreRecTrace((int)key);
    }
  }
}
